package com.tj.collection.db.dao.impl;
import cn.hutool.core.date.DateField;
import cn.hutool.core.date.DateUtil;
import com.fqgj.common.base.AbstractBaseMapper;
import com.fqgj.common.utils.CollectionUtils;
import com.google.common.collect.Maps;
import com.tj.collection.db.dao.RptChatterOnlinePreHourDao;
import com.tj.collection.db.entity.RptChatterOnlinePreHourEntity;
import org.springframework.stereotype.Repository;

import java.util.Date;
import java.util.HashMap;
import java.util.List;

/**
* User: linqu
* Date: 2023-11-20
* Time: 19:09:44.045
*/

@Repository
public class RptChatterOnlinePreHourDaoImpl extends AbstractBaseMapper<RptChatterOnlinePreHourEntity> implements RptChatterOnlinePreHourDao {
    @Override
    public List<RptChatterOnlinePreHourEntity> listChatterOnlinePreHour() {
        final HashMap<String, Object> params = Maps.newHashMap();
        params.put("createDt", Integer.valueOf(DateUtil.format(new Date(), "yyyyMMdd")));
        params.put("createHour", DateUtil.hour(new Date(), Boolean.TRUE));
        return this.getSqlSession().selectList(this.getStatement("listChatterOnlinePreHour"), params);
    }

    @Override
    public Integer getOnlineTotal(Date startDate, Date endDate) {
        final HashMap<String, Object> params = Maps.newHashMap();
        params.put("startDate", startDate);
        params.put("endDate", endDate);
        return this.getSqlSession().selectOne(this.getStatement("getOnlineTotal"), params);
    }

    @Override
    public int removeChatterOnlinePreHour() {
        final HashMap<String, Object> params = Maps.newHashMap();
        params.put("createDt", Integer.valueOf(DateUtil.format(new Date(), "yyyyMMdd")));
        params.put("createHour", DateUtil.hour(new Date(), Boolean.TRUE));
        return this.getSqlSession().delete(this.getStatement("removeChatterOnlinePreHour"), params);

    }

    @Override
    public List<RptChatterOnlinePreHourEntity> listChatterOnline(String chatterCode, Integer startDate, Integer endDate) {
        final HashMap<String, Object> params = Maps.newHashMap();
        params.put("chatterCode", chatterCode);
        params.put("startDate", startDate);
        params.put("endDate", endDate);
        return this.getSqlSession().selectList(this.getStatement("listChatterOnline"), params);

    }

    @Override
    public List<RptChatterOnlinePreHourEntity> getOnlineUserTotal(Date startDate, Date endDate) {
        final HashMap<String, Object> params = Maps.newHashMap();
        params.put("startDate", startDate);
        params.put("endDate", endDate);
        return this.getSqlSession().selectList(this.getStatement("getOnlineUserTotal"), params);
    }
}